import java.util.*;
public class _16 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int a[]= new int[n];
        long sum=0l;
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
            sum+=a[i];
        }
        int right=n-1,left=0;
        long max=sum;
        while(right>left){
            if(a[right]>a[left]){
                sum-=a[left];
                //System.out.println(sum+"1");
                left++;
                max=Math.max(max, sum);
            }else if(a[right]<a[left]){
                sum-=a[right];
                //System.out.println(sum+"2");
                right--;
                max=Math.max(max, sum);
            }else {
                sum-=a[right];
                right--;
                //System.out.println(sum+"3");
                max=Math.max(max, sum);
            }
        }
        System.out.println(max);
    }
   
}


